/*
Copyright 2010 Johan Maasing

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package nu.zoom.catonine.prefs.gui.impl;

import javax.swing.JCheckBoxMenuItem;

import nu.zoom.catonine.prefs.gui.PreferencesGUI;
import nu.zoom.swing.desktop.PlugIn;
import nu.zoom.swing.desktop.Workbench;
import nu.zoom.swing.desktop.WorkbenchListener;
import nu.zoom.ui.Resources;
import nu.zoom.ui.Resources.ResourceNotFoundException;

/**
 * @author Johan Maasing
 * 
 */
public class PreferencesGUIPlugIn implements PlugIn, WorkbenchListener {
	private final Workbench workbench;
	private final PreferencesGUI preferencesGUI;
	private final Resources resources;

	public PreferencesGUIPlugIn(final Workbench workbench, final PreferencesGUI preferencesGUI,
			final Resources resources) {
		super();
		this.workbench = workbench;
		this.preferencesGUI = preferencesGUI;
		this.resources = resources;
	}

	@Override
	public void start() {
		try {
			OpenPreferencesAction openAction = new OpenPreferencesAction(this.preferencesGUI, this.resources);
			JCheckBoxMenuItem menuItem = openAction.getControl();
			workbench.getMenuBar().addToApplicationMenu(menuItem);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (ResourceNotFoundException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void close() {
	}

	@Override
	public void initialize() {
		workbench.addWorkBenchListener(this);
	}

	@Override
	public void visible() {
	}
}
